In [1]:
from konfoo import Index, Byteorder, Enumeration, Enum, Enum8, Enum16, Enum24, Enum32, Enum64
Item type of the field
class.
In [2]:
Enum.item_type
Out[2]:
Checks if the field
class is a bit
field.
In [3]:
Enum.is_bit()
Out[3]:
Checks if the field
class is a boolean
field.
In [4]:
Enum.is_bool()
Out[4]:
Checks if the field
class is a decimal
number field.
In [5]:
Enum.is_decimal()
Out[5]:
Checks if the field
class is a floating point
number field.
In [6]:
Enum.is_float()
Out[6]:
Checks if the field
class is a pointer
field.
In [7]:
Enum.is_pointer()
Out[7]:
Checks if the field
class is a stream
field.
In [8]:
Enum.is_stream()
Out[8]:
Checks if the field
class is a string
field.
In [9]:
Enum.is_string()
Out[9]:
In [10]:
class Validity(Enumeration):
error = 0
correct = 1
forced = 2
undefined = 3
In [11]:
enum = Enum(bit_size=2, align_to=None, enumeration=None, byte_order='auto')
In [12]:
enum = Enum(2, enumeration=Validity)
In [13]:
enum
Out[13]:
In [14]:
str(enum)
Out[14]:
In [15]:
repr(enum)
Out[15]:
In [16]:
enum.name
Out[16]:
In [17]:
enum.index
Out[17]:
Byte index
of the field
within the byte stream
.
In [18]:
enum.index.byte
Out[18]:
Bit offset relative to the byte index
of the field
within the byte stream
.
In [19]:
enum.index.bit
Out[19]:
Absolute address of the field
within the data source
.
In [20]:
enum.index.address
Out[20]:
Base address of the byte stream
within the data source
.
In [21]:
enum.index.base_address
Out[21]:
Indexes the field
and returns the index
after the field
.
In [22]:
enum.index_field(index=Index())
Out[22]:
In [23]:
enum.alignment
Out[23]:
Byte size of the field group
which the field
is aligned to.
In [24]:
enum.alignment.byte_size
Out[24]:
Bit offset of the field
within its aligned field group
.
In [25]:
enum.alignment.bit_offset
Out[25]:
In [26]:
enum.bit_size
Out[26]:
In [27]:
enum.byte_order
Out[27]:
In [28]:
enum.byte_order.value
Out[28]:
In [29]:
enum.byte_order.name
Out[29]:
In [30]:
enum.byte_order = 'auto'
In [31]:
enum.byte_order = Byteorder.auto
Checks if the decimal field
is signed or unsigned.
In [32]:
enum.signed
Out[32]:
Maximal decimal field
value.
In [33]:
enum.max()
Out[33]:
Minimal decimal field
value.
In [34]:
enum.min()
Out[34]:
Returns the enum field
value as an enum name string or an unsigned integer number.
In [35]:
enum.value
Out[35]:
Returns the decimal field
value aligned to its field group
as a number of bytes.
In [36]:
bytes(enum)
Out[36]:
In [37]:
bytes(enum).hex()
Out[37]:
Returns the decimal field
value as an integer number.
In [38]:
int(enum)
Out[38]:
Returns the decimal field
value as an floating point number.
In [39]:
float(enum)
Out[39]:
Returns the decimal field
value as a lowercase hexadecimal string prefixed with 0x
.
In [40]:
hex(enum)
Out[40]:
Returns the decimal field
value as a binary string prefixed with 0b
.
In [41]:
bin(enum)
Out[41]:
Returns the decimal field
value as an octal string prefixed with 0o
.
In [42]:
oct(enum)
Out[42]:
Returns the decimal field
value as a boolean value.
In [43]:
bool(enum)
Out[43]:
Returns the decimal field
value as a signed integer number.
In [44]:
enum.as_signed()
Out[44]:
Returns the decimal field
value as an unsigned integer number.
In [45]:
enum.as_unsigned()
Out[45]:
Returns the meatadata
of the field
as an ordered dictionary.
In [46]:
enum.describe()
Out[46]:
In [47]:
enum.deserialize(bytes.fromhex('01'), byte_order='little')
Out[47]:
In [48]:
enum.value
Out[48]:
In [49]:
bytes(enum)
Out[49]:
In [50]:
bytes(enum).hex()
Out[50]:
In [51]:
int(enum)
Out[51]:
In [52]:
float(enum)
Out[52]:
In [53]:
hex(enum)
Out[53]:
In [54]:
bin(enum)
Out[54]:
In [55]:
oct(enum)
Out[55]:
In [56]:
bool(enum)
Out[56]:
In [57]:
buffer = bytearray()
In [58]:
enum.value = 1
In [59]:
enum.value = 1.0
In [60]:
enum.value = 0x1
In [61]:
enum.value = 0b1
In [62]:
enum.value = 0o1
In [63]:
enum.value = True
In [64]:
enum.value = 'correct'
In [65]:
enum.serialize(buffer, byte_order='little')
Out[65]:
In [66]:
buffer.hex()
Out[66]:
In [67]:
bytes(enum).hex()
Out[67]:
In [ ]: